import { defineStore } from 'pinia'
import { sessionCache } from '@/utils/cache'

const useUserStore = defineStore('user', {
  state: () => {
    return {
      userInfo: sessionCache.getCache('userInfo') ?? null,
      avatarUrl: sessionCache.getCache('avatar') ?? null,
      nickname: sessionCache.getCache('nickname') ?? null,
    }
  },
  actions: {
    changeAvatar(avatar: string) {
      this.avatarUrl = avatar
    },
    changeNickname(nickname: string) {
      this.nickname = nickname
    },
  },
})

export default useUserStore
